using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Runtime.Serialization;
using DIS_DAL_WS.Models;

namespace DIS_DAL_WS.DTO
{
    [DataContract]
	public class NationalPromotionDTO
	{
        [DataMember]
		public int ID { get; set; }
        [DataMember]
		public int IDItem { get; set; }
        [DataMember]
		public double Discount { get; set; }
        [DataMember]
        public ItemDTO Item { get; set; }

        public static NationalPromotionDTO Translate(NationalPromotion Entity)
        {
            if (Entity != null)
            {
                var dto = new NationalPromotionDTO
                {
                    ID = Entity.ID,
                    Discount = Entity.Discount == null ? 0 : Entity.Discount.Value,
                    Item = ItemDTO.Translate(Entity.Item)
                };
                if (Entity.IDItem != null)
                {
                    dto.IDItem = Entity.IDItem.Value;
                }
                return dto;
            }
            return null;
        }

        public static NationalPromotion Reverse(NationalPromotionDTO obj)
        {
            var entity = new NationalPromotion
            {
                ID = obj.ID,
                Discount = obj.Discount
            };
            if (obj.IDItem != -1)
            {
                entity.IDItem = obj.IDItem;
            }
            return entity;
        }

        public void UpdateEntity(ref NationalPromotion entity)
        {
            entity.Discount = Discount;
            if (IDItem != -1)
            {
                entity.IDItem = IDItem;
            }
        }
	}
}